<template>
  <div class="main_box">
    <el-row>
      <el-col :span="12">
        <Crumbs></Crumbs>
      </el-col>
      <el-col :span="12">
        <div class="opration_wrap">
          <el-button type="primary" icon="fa fa-mail-forward" @click="returnList">返回</el-button>
        </div>
      </el-col>
    </el-row>
    <div class="add_wrap">
      <div class="tit">
        <h2>编辑商品规格</h2>
      </div>
      <el-form :model="editForm" ref="editForm" label-width="200px" :rules="roleRules">
        <el-row>
          <el-form-item label="医院名称：" >
            <span>{{editForm.institutionName}}</span>
          </el-form-item>

          <el-form-item label="规格名称" prop="specName">
            <el-input v-model="editForm.specName"></el-input>
          </el-form-item>
          <el-form-item label="规格值(多个以英文逗号隔开)" prop="specValue">
            <!--<el-input v-model="editForm.specValue"></el-input>-->
            <el-input type="textarea" v-model="editForm.specValue" placeholder="请输入规格值"></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="specNote">
            <el-input type="textarea" v-model="editForm.specNote" placeholder="请输入备注"></el-input>
          </el-form-item>
        </el-row>

        <el-row>
          <el-form-item>
            <el-button type="primary" @click="sureClick">保 存</el-button>
            <el-button @click="returnList">取 消</el-button>
          </el-form-item>
        </el-row>
      </el-form>
    </div>
  </div>
</template>

<script>

  import * as message from "@/constants/message"
  import Crumbs from "@/components/Crumbs"
  import Region from "@/components/Region"

  export default{
    data(){
      return {
        editForm:{
          specId:"",
          institutionName:"",
          specName:"",
          specValue:"",
          specNote:""
        },
        roleRules: {
          specName: [
            {required: true, message: "请输入规格名称", trigger: "blur"}
          ],
          specValue: [
            {required: true, message: "请输入规格值", trigger: "blur"}
          ],
          specNote: [
            { max: 151, message: '长度不超过150个字', trigger: 'blur' }
          ],
        }
      }
    },
    components: {
      Crumbs,
      Region
    },
    methods: {
      int(){
        this.getData();
      },
      getData(){
        this.$Get(this.$Config.api.goodsSpec,{specId:this.$route.query.id})
          .then(res => {
            this.$Utils.bindingBean(this.editForm, res.data);
          })
      },
      sureClick() {
        this.$refs.editForm.validate(valid => {
          if (valid) {
            this.$confirm(message.MSG_CONFIRM_SAVE_ALTER, message.TITLE_PROMPT, {})
              .then(() => {
                this.editInstitutionTrade();
              });
          }
        })
      },
      editInstitutionTrade() {
        let data = {
          specId: this.editForm.specId,
          specName: this.editForm.specName,
          specValue: this.editForm.specValue,
          specNote: this.editForm.specNote
        };
        this.$Put(this.$Config.api.goodsSpec, data)
          .then(data => {
            this.$notify.success({
              title: message.TITLE_SUCCESS,
              message: message.MSG_ACTION_SUCCESS
            });
            this.returnList();
          })
          .catch(error => {
            if (error.msg) {
              this.$notify.error({
                title: message.TITLE_ERROR,
                message: error.msg
              });
            }
          })
      },

      returnList(){
        this.$router.push({path: '/good/goodsSpecManagement'})
      },
    },


    mounted(){
      this.int();
    }
  }
</script>
<style lang="scss" src="@/assets/css/views/add.scss" scope>
</style>
